#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<string.h>

void bo_sort(int a[25],int len){
	int i,j;
	for(i = 0;i < len-1;i++){
		for(j = 0;j < len - i - 1;j++){
			if(a[j] > a[j+1]){
				int t = a[j];
				a[j] = a[j + 1];
				a[j + 1] = t;
			}
		}
	}
}

void locate(int m,int* x,int* y,int o[5][5]){
	
	int i,j ;
	for( i = 0;i < 5;i++){
		for( j = 0;j < 5;j++){
			if(m == o[i][j]){
				*x = i;
				*y = j;
				break;
			}
		}
	}
	
}

void fun_c(int a[25],int o[5][5],int m){
	int x,y;
	
	locate(m,&x,&y,o);
	int t_max = o[2][2];
	o[2][2] = m;
	o[x][y] = t_max;
	
	locate(a[0],&x,&y,o);
	int t1_min = o[0][0];
	o[0][0] = a[0];
	o[x][y] = t1_min;
	
	locate(a[1],&x,&y,o);
	int t2_min = o[0][4];
	o[0][4] = a[1];
	o[x][y] = t2_min;
	
	locate(a[2],&x,&y,o);
	int t3_min = o[4][0];
	o[4][0] = a[2];
	o[x][y] = t3_min;
	
	locate(a[3],&x,&y,o);
	int t4_min = o[4][4];
	o[4][4] = a[3];
	o[x][y] = t4_min;
}

int main(){
	int arr_op[5][5],arr_ou[5][5],arr_s[25];
	
	for (int i = 0; i < 5; i++){
		scanf("%d%d%d%d%d", &arr_op[i][0], &arr_op[i][1], &arr_op[i][2], &arr_op[i][3], &arr_op[i][4]);
	}
	memcpy(arr_ou,arr_op,100);
	memcpy(arr_s,arr_op,100);
	int max = arr_op[0][0];
	for (int i = 0; i < 5; i++){
		for (int j = 0; j < 5; j++){
			if (arr_op[i][j] > max){
				max = arr_op[i][j];
			}
		}
	}
	
	bo_sort(arr_s,25);
	fun_c(arr_s,arr_ou,max);
	
	for(int i = 0;i < 5;i++){
		for(int j = 0;j < 5;j++){
			printf("   %d",arr_ou[i][j]);
		}
		printf("\n");
	}
	return 0;
}
